<template>
  <div>
    <div class="add" @click="add" v-if="this.active === 0">新增</div>
    <eagle-tab-page-list
      url="/PlanSimpleDrillPlan/GetPageData"
      :params="params"
      :filterParams="filterParams"
      :filterTab="filterTab"
      :activeFilter="activeFilter"
      @initActive="_initActive"
      @initList="_initList"
      ref="eagleTabPageList"
    >
      <div v-if="this.active === 0">
        <eagle-cell class="card" v-for="(item, index) in list" :key="index">
          <eagle-tag v-if="item.Status === 100" class="info_tag" type="normal"
            >已完成
          </eagle-tag>
          <eagle-tag v-if="item.Status === 15" class="info_tag" type="warning"
            >审批中
          </eagle-tag>
          <eagle-tag v-if="item.Status === 10" class="info_tag" type="danger"
            >待发布
          </eagle-tag>
          <div>
            <div @click="goToDetail(item)">
              <eagle-row>
                <eagle-col span="24">
                  <h3>{{ item.DrillName }}</h3>
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20" class="dep_sort">
                <eagle-col span="24">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_date.png"
                    alt=""
                  />年度：{{ item.Year }}</eagle-col
                >
              </eagle-row>
              <eagle-row gutter="20" class="dep_sort">
                <eagle-col span="24">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_detail.png"
                    alt=""
                  />对应预案：{{ item.FileName }}
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20" class="dep_sort">
                <eagle-col span="24">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_type.png"
                    alt=""
                  />预案类型：{{ item.PlanTypeName }}
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20" class="dep_sort">
                <eagle-col span="24">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_type.png"
                    alt=""
                  />演练类型：{{ item.DrillTypeName }}
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20" class="dep_sort">
                <eagle-col span="24">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_type.png"
                    alt=""
                  />演练范围：{{ item.DrillRange }}
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20" class="dep_sort">
                <eagle-col span="24">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_date.png"
                    alt=""
                  />开始日期：{{ getDate(item.DrillStartDate) }}
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20" class="dep_sort">
                <eagle-col span="24">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_date.png"
                    alt=""
                  />结束日期：{{ getDate(item.DrillEndDate) }}
                </eagle-col>
              </eagle-row>
              <eagle-divider />
              <eagle-button
                class="ml-10 mt-10"
                style="float: right;height:30px;"
                size="small"
                type="default"
                v-if="item.Status === 10"
                @click.stop="del(item)"
                >删除
              </eagle-button>
              <eagle-button
                class="ml-10 mt-10"
                style="float: right;height:30px;"
                size="small"
                type="default"
                v-if="item.Status === 10"
                @click.stop="edit(item)"
                >编辑
              </eagle-button>
              <eagle-button
                class="ml-10 mt-10"
                style="float: right;height:30px;"
                size="small"
                type="default"
                v-if="item.Status != 10"
                @click.stop="history(item)"
                >审批历史
              </eagle-button>
            </div>
          </div>
        </eagle-cell>
      </div>
      <div v-if="this.active === 1">
        <eagle-cell class="card" v-for="(item, index) in list" :key="index">
          <eagle-tag
            v-if="item.DrillStatus === 100"
            class="info_tag"
            color="#1989fa"
            >已完成
          </eagle-tag>
          <eagle-tag
            v-if="item.DrillStatus === 15"
            class="info_tag"
            type="warning"
            >进行中
          </eagle-tag>
          <eagle-tag
            v-if="item.DrillStatus === 10"
            class="info_tag"
            type="danger"
            >未开始
          </eagle-tag>
          <div>
            <div>
              <eagle-row>
                <eagle-col span="24">
                  <h3>{{ item.DrillName }}</h3>
                </eagle-col>
              </eagle-row>
              <eagle-file-list
                :attachs="item.PlanAttachs"
                :labelName="'演练方案:'"
              ></eagle-file-list>
              <eagle-file-list
                :attachs="item.DrillAttachs"
                :labelName="'演练记录:'"
              ></eagle-file-list>
              <eagle-file-list
                :attachs="item.ScriptAttachs"
                :labelName="'演练脚本:'"
              ></eagle-file-list>
              <van-divider />
              <eagle-button
                class="ml-10 mt-10"
                style="float: right;height:30px;"
                size="small"
                type="default"
                @click.stop="editT(item)"
                >编辑
              </eagle-button>
              <eagle-button
                class="ml-10 mt-10"
                style="float: right;height:30px;"
                size="small"
                type="default"
                v-if="item.DrillStatus === 100"
                @click.stop="goToDetailList(item)"
                >详情
              </eagle-button>
            </div>
          </div>
        </eagle-cell>
      </div>
    </eagle-tab-page-list>
  </div>
</template>

<script>
import { getDate } from "@/utils/getDate.js";
export default {
  data() {
    return {
      active: 0,
      list: [],
      params: [
        {
          title: "应急演练计划",
          dataType: "List",
        },
        {
          title: " 演练准备与实施",
          dataType: "PartList",
        },
      ],
      showTab: false,
      filterTab: false,
      filterParams: [
        {
          name: "DrillStatus",
          title: "演练状态",
          originTitle: "演练状态",
          dataType: "int",
          data: [
            { text: "不限", value: "" },
            { text: "未开始", value: "10" },
            { text: "进行中", value: "15" },
            { text: "已完成", value: "100" },
          ],
        },
      ],
      activeFilter: [
        {
          active: 0,
          filter: false,
        },
      ],
    };
  },
  methods: {
    _initActive(active) {
      if (active === 1) {
        this.filterTab = true;
      }
      if (active === 0) {
        this.filterTab = false;
      }
      this.active = active;
    },
    _initList(list) {
      this.list = list;
    },
    _fileUploadCb(attachs) {
      this.form.Attach = attachs;
    },
    getDate(data) {
      return getDate(data);
    },
    goFile(attachCode) {
      this.$router.push("/Attach/AatachDetail?attCode=" + attachCode);
    },
    del(item) {
      const _this = this;
      const id = item.ID;
      this.$dialog
        .confirm({
          title: "询问",
          message: "您确定删除本条记录吗？",
        })
        .then(() => {
          _this.$axios
      	  .get("/PlanSimpleDrillPlan/Delete",{params:{ id: item.ID }})
          .then((res) => {
            _this.$toast.success("删除成功！");
            _this.$refs.eagleTabPageList.getList();
          });
        })
        .catch(() => {
          // on cancel
        });
    },
    add() {
      this.$router.push({
        path: "/PlanSimpleDrillPlanAdd",
        query: { id: 0 },
      });
    },
    edit(item) {
      this.$router.push({
        path: "/PlanSimpleDrillPlanEdit",
        query: { id: item.ID },
      });
    },
    editT(item) {
      this.$router.push({
        path: "/PlanSimpleDrillPlanImplementEdit",
        query: { id: item.ID },
      });
    },
    history(item) {
      
      this.$router.push({
        path: "/Common/ApproveHistory",
        query: {
          recordID: item.ID,
          opController: "PlanSimpleDrillPlan",
          operate: "publish",
        },
      });
    },
    goToDetail(item) {
      this.$router.push({
        path: "/PlanSimpleDrillPlanView",
        query: { id: item.ID, isShow: true },
      });
    },
    goToDetailList(item) {
      this.$router.push({
        path: "/PlanSimpleDrillPlanImplementView",
        query: { id: item.ID, isEdit: true },
      });
    },
  },
};
</script>

<style lang="less" scoped>
.risk {
  height: 100vh;
  background-color: #e8f1f8;
  .info_search {
    padding: 10px;
    border-radius: 5px !important;
    .van-field__control {
      background-color: #ffffff !important;
    }
  }
}
.all_dep {
  background-color: #ffffff;
}
.warn_item {
  margin: 10px;
  border-radius: 5px;
  position: relative;
}
.dep_sort {
  img {
    height: 15px;
    width: 15px;
    margin-right: 5px;
  }
}
.card_check {
  border-radius: 8px;
}
.dep_btm {
  display: flex;
  justify-content: flex-end;
  width: 30%;
  float: right;
  .btm_item {
    display: flex;
    align-items: center;
    img {
      height: 15px;
      width: 15px;
      margin-right: 5px;
    }
  }
}
</style>
